-- 隐报仇毒
local yinbaochoudu = fk.CreateSkill {
    name = "mcdh_yinbaochoudu",
}

yinbaochoudu:addEffect(fk.AfterCardsMove,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if not player:hasSkill(self) then return false end
            for _, move in ipairs(data) do
                local to = player.room:getPlayerById(move.to)
                if move.to and move.to ~= player.id and move.toArea == Card.PlayerHand
                        and not to.dead and to.phase == Player.NotActive then
                    return true
                end
            end
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
            for _, move in ipairs(data) do
                local to = room:getPlayerById(move.to)
                if move.to and move.to ~= player.id and move.toArea == Card.PlayerHand and not to.dead and to.phase == Player.NotActive then
                    room:addPlayerMark(to, "@mcdh_yinbaochoudu", #move.moveInfo)
                end
            end
    end
})

yinbaochoudu:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if not player:hasSkill(self) then return false end
        return player == target and player.phase == Player.Start and table.find(
                        room.alive_players,
                        function(p)
                            return p:getMark("@mcdh_yinbaochoudu") >= p.maxHp
                        end
                        )
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.map(
                    table.filter(
                            room.alive_players,
                            function(p)
                                return p:getMark("@mcdh_yinbaochoudu") >= p.maxHp
                            end
                    ),
                    Util.IdMapper
            )
        local pids = room:askForChoosePlayers(
                    player,
                    targets,
                    1, #targets,
                    "#mcdh_yinbaochoudu-choice",
                    self.name
            )
        if #pids > 0 then
            self.cost_data = pids
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        for _, pid in ipairs(self.cost_data) do
            local to = room:getPlayerById(pid)
            room:removePlayerMark(to, "@mcdh_yinbaochoudu", to.maxHp)
        end
        for _, pid in ipairs(self.cost_data) do
            local to = room:getPlayerById(pid)
            room:loseHp(to, 1, self.name)
        end
    end
})

return yinbaochoudu